package com.hypo.controller;

import com.hypo.annotation.LogOperation;
import com.hypo.pojo.*;
import com.hypo.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/emps")
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    /**
     * 回显
     */
    @LogOperation
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        return Result.success(empService.getInfo(id));
    }
    /**
     * 修改员工
     */
    @PutMapping
    public Result modify(@RequestBody Emp emp){
        empService.modify(emp);
        return Result.success();
    }
    /**
     * 批量删除员工
     */
    @DeleteMapping
    public Result del(@RequestParam List<Integer> ids) {
        empService.del(ids);
        return Result.success();
    }


    /***
     * 分页查询
     */
    @GetMapping
    public Result page(EmpQueryParam empQueryParam) {
        // 调用Service查询->PageResult
        PageResult pageResult = empService.page(empQueryParam);
        //响应数据
        return Result.success(pageResult);
    }

    /**
     * 新增员工
     */
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        empService.save(emp);
        return Result.success();
    }

    /**
     * 班主任
     */
    @GetMapping("/list")
    public Result findAll(Emp emp) {
        return Result.success(empService.findAll(emp));
    }

}